package cn.kgc.mst.util;

import cn.kgc.mst.common.Const;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 韩
 * //@Order(0)定义了组件的加载顺序，值越小，越优先加载
 * <p>
 * 在当前类里将数据源切换成了从数据源，因为要走查的操作
 * </p>
 */
@Aspect
@Component
@Order(0)
@Slf4j
public class DataSourceInterceptor {

    //* cn.kgc.ssmmodulardemo.service.*.*(..))
    //* cn.kgc.mst.service.query*(..)
    //public * net.aazj.service..*.getUser(..)
    @Pointcut("execution(* cn.kgc.mst.service.*Service.query*(..))")
    public void dataSourceMaster() {
    }

    @Before("dataSourceMaster()")
    public void before(JoinPoint jp) {
        log.info("执行.....");
        MultipleDataSource.setDataSourceKey(Const.DATA_SOURCE_SLAVE);
    }

}
